<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="database" scope="request" class="accessibleworldsdatabase.AccessibleWorldsDatabaseJavaBeans"/>
<jsp:useBean id="des" scope="request" class="accessibleworldsdes.AccessibleWorldsDESJavaBeans"/>
<%try {
	
String accessCode = request.getParameter("accessCode");

if(!(accessCode==null || "".equals(accessCode))) {
	
    accessCode = des.decryptString(session.getId(), accessCode);
    accessCode = URLDecoder.decode(accessCode, "UTF-8");

    if(des.getAndroidAccessCode().equals(accessCode) || des.getComputerAccessCode().equals(accessCode)) {
    	
        String userID = request.getParameter("userID");
        String status = request.getParameter("status");
        String type = request.getParameter("type");
        String title = request.getParameter("title");
        String description = request.getParameter("description");
        String latitude = request.getParameter("latitude");
        String longitude = request.getParameter("longitude");
                
        if(!(userID==null || "".equals(userID) || 
				title==null || "".equals(title) || description==null ||"".equals(description) ||
        		status==null ||"".equals(status) || type==null ||"".equals(type) ||
            	latitude==null || "".equals(latitude) || longitude==null ||"".equals(longitude))) {
            
            userID = des.decryptString(session.getId(), userID);
            status = des.decryptString(session.getId(), status);
            type = des.decryptString(session.getId(), type);
            title = des.decryptString(session.getId(), title);
            description = des.decryptString(session.getId(), description);
            latitude = des.decryptString(session.getId(), latitude);
            longitude = des.decryptString(session.getId(), longitude);
            
            userID = URLDecoder.decode(userID, "UTF-8");
            status = URLDecoder.decode(status, "UTF-8");
            type = URLDecoder.decode(type, "UTF-8");
            title = URLDecoder.decode(title, "UTF-8");
            description = URLDecoder.decode(description, "UTF-8");
            latitude = URLDecoder.decode(latitude, "UTF-8");
            longitude = URLDecoder.decode(longitude, "UTF-8");
            
            database.connect(des.decryptString(des.getServiceSecretKey(), database.getEncryptedPassword()));
            
            String SQL =
            "INSERT INTO Reports"+
            	" (user_id"+
            	" ,status"+
            	" ,v_id"+
            	" ,title"+
            	" ,description"+
            	" ,latitude"+
            	" ,longitude)"+
            	" VALUES"+
            		" ("+userID+""+
            		" ,\""+status+"\""+
            		" ,"+type+""+
            		" ,\""+title+"\""+
            		" ,\""+description+"\""+
            		" ,"+latitude+""+
                    " ,"+longitude+")";
                        
            ResultSet resultSet = database.updateSQLWithGeneratedKeys(SQL);
            String reportID = "";
            if(resultSet.next()) {
                reportID = ""+resultSet.getInt(1);
            }
            
            String output = URLEncoder.encode("OK","UTF-8");
            output = output+" "+URLEncoder.encode(reportID,"UTF-8");
            
            output = des.encryptString(session.getId(),output);
            out.print(output);
            
            database.closeConnection();
       }
    }
}
} catch (Exception ex) {}%>